home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3886 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  58 lines

  1. Path: news2.ios.com!usenet
  2. From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Visual C++ 4.0 lacking initializers?
  5. Date: Fri, 26 Jan 1996 14:05:56 GMT
  6. Organization: Internet Online Services
  7. Message-ID: <4eamnb$q16@news2.ios.com>
  8. References: <31049C46.A26@oz.is>
  9. NNTP-Posting-Host: ppp-37.ts-7.hck.idt.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Hßlfdan Ingvarsson <halfdan@oz.is> wrote:
  13.  
  14. >Is it me or is this sort of code not possible with VC++ 4.0? 
  15.  
  16. >// Declarations of class Foo
  17.  
  18. >// VC++ Complains about the line below with the error
  19. >// error C2436: '__ctor' : cannot initialize member functions
  20. >Foo::Foo(void) : Foo::Foo(10) {}
  21.  
  22. >Foo::Foo(x)
  23. >{
  24. >  // Some stuff
  25. >}
  26.  
  27. I think, that a constructor can call constructors of immediate
  28. superclasses or initializers of member data. That's why compiler
  29. thinks that Foo::Foo(10) is some initializer. Anyway it it would be
  30. legal, you should write 
  31.  
  32. Foo::Foo
  33.  : Foo(10)
  34.     {}
  35.  
  36. But but from clearness point of view it is better to write:
  37.  
  38.   Foo::Foo()
  39.     : x(1)
  40.        {}
  41.  
  42. if you have no value to initialize, then write:
  43.  
  44. Foo::initialize(int i)
  45.  { 
  46.     .... do something with i
  47.  }
  48.  
  49. Foo::Foo()
  50.  {
  51.    initialize(10);
  52.  }
  53. *******************************************
  54. *    Vlastimil Adamovsky                  *
  55. * Smalltalk, C++ and Envelop development  *
  56. *******************************************
  57.  
  58.